﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace syncPrice
{
       
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void btnSyncPrice_Click(object sender, EventArgs e)
        {
            //justAtest();

            syncPrice();
        }

        /// <summary>
        /// 同步成本价格
        /// </summary>
        private void syncPrice()
        {
            BZZ.DataAcess worker = new BZZ.DataAcess();
            string sql = "update inventory set cInvDefine2=iInvNcost where  not iInvNcost is null and cInvDefine2<>iInvNcost";
            iii++;
            int x = worker.ExecuteNonQuery(sql);
            //lblMessage.Text = x.ToString() + " rows has effected.exeNum:"+iii.ToString();
            lblMessage.Text = "上次同步时间是：" + DateTime.Now.ToString(); ;
        }

        /// <summary>
        /// 测试而已，无用
        /// </summary>
        private void justAtest()
        {
            BZZ.DataAcess worker = new BZZ.DataAcess();
            string sql = "select count(*) from inventory";
            int x = worker.ExecuteCount(sql);
            lblMessage.Text = x.ToString() + " rows has effected.";
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Interval = 60 * 1000;
            timer1.Enabled = true;
            syncPrice();
            //notifyIcon1.Visible = false;
            //this.Close();
        }
        private int iii = 0;
        private void timer1_Tick(object sender, EventArgs e)
        {
            syncPrice();
        }



        protected override void OnClosing(CancelEventArgs e)
        {
            Hide();
            this.ShowInTaskbar = false;
            notifyIcon1.Visible = true;
            e.Cancel = true;
        }

        private void menuShow_Click(object sender, EventArgs e)
        {
            Show();
        }

        private void menuExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

    }
}
